using System;
using UnityEngine;
using Voodoo.Pattern;

public class CoinFxEmitter : SingletonMB<CoinFxEmitter>
{
	[SerializeField]
	private MovingFx m_CoinUIPrefab;

	private GameObject m_CurrentCoinContainer;

	public void EmitFxToward(CoinFxReceiver _Receiver, Vector2 _AnchoredEmitPosition, Action OnCompleted = null)
	{
		if ((bool)m_CurrentCoinContainer)
		{
			UnityEngine.Object.Destroy(m_CurrentCoinContainer);
		}
		Transform parent = _Receiver.transform.parent;
		m_CurrentCoinContainer = new GameObject("CoinFxContainer");
		RectTransform rectTransform = m_CurrentCoinContainer.AddComponent<RectTransform>();
		m_CurrentCoinContainer.transform.parent = parent;
		rectTransform.anchorMin = _Receiver.m_RectTransform.anchorMin;
		rectTransform.anchorMax = _Receiver.m_RectTransform.anchorMax;
		rectTransform.anchoredPosition = Vector2.zero;
		rectTransform.sizeDelta = Vector2.zero;
		for (int i = 0; i < 30; i++)
		{
			MovingFx movingFx = UnityEngine.Object.Instantiate(m_CoinUIPrefab, m_CurrentCoinContainer.transform);
			movingFx.m_RectTransform.anchoredPosition = _AnchoredEmitPosition;
			movingFx.m_RectTransform.Rotate(new Vector3(0f, 0f, 360f.Range()));
			if (i == 29)
			{
				movingFx.Emit(_Receiver.m_RectTransform.anchoredPosition, delegate
				{
					OnCompleted?.Invoke();
				});
			}
			else
			{
				movingFx.Emit(_Receiver.m_RectTransform.anchoredPosition, delegate
				{
					SingletonMB<GameManager>.Instance.GameplayHaptic.PlayHaptic(HapticType.Small);
				});
			}
		}
	}
}
